/*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <sourcemod>
#include <sdktools>

#include "macros.sp"
#include "helpers.sp"
#include "sqlhelpers.sp"

new bool:server_was_start = false;

public OnMapStart()
{
        if(!server_was_start)
        {
                server_was_start = true;
                maps_choosing_select_less_played_all_case(GetConVarInt(FindConVar("rev_server_id")), do_change_map);
        }
}

public do_change_map(Handle:owner, Handle:hndl, const String:error[], any:junk)
{
        IF_VALID_RESULT(0)
        {
                if(SQL_FetchRow(hndl)) /* check what kind of map */
                {
                        decl String:map[32];
                        SQL_FetchString(hndl, 0, map, sizeof(map));
                        ServerCommand("changelevel %s", map);   //Change the campaign
                        return;
                }
        }

        ServerCommand("changelevel c1m1_hotel");        //Change the campaign
}
